package com.zcx.qshop.conn;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

@HttpInlet(Conn.INLET_JSON_SHOPCART)
public class JsonShopcartAsyGet extends QSAsyGet<JsonShopcartAsyGet.Info> {
	
	public String uid, areaid;
	
	public JsonShopcartAsyGet(String uid, String areaid, AsyCallBack<Info> asyCallBack) {

		super(asyCallBack);
		
		this.uid = uid;

		this.areaid = areaid;
		
 	}
	
	@Override
	public Info parser(JSONObject object) {
		
		if(object.optString("message").equals("1")){
			
			Info info = new Info();
			
			JSONArray array = object.optJSONArray("shopcartlist");
			
			for (int i = 0; i < array.length(); i++) {
				
				Info.Shop shop = new Info.Shop();
				
				JSONObject o = array.optJSONObject(i);
				
				shop.cid = o.optString("cid");

				shop.title = o.optString("title");
				
				shop.picurl = Conn.SERVICE + o.optString("picurl");
				
				shop.price = o.optDouble("price");
				
				shop.unit = o.optString("unit");
				
				shop.number = o.optInt("number");

				shop.one = o.optString("one");

				shop.two = o.optString("two");

				info.pids.add(shop.pid = o.optString("pid"));
				
				info.shops.add(shop);
				
			}
			
			return info;
			
		}
		
		return null;
		
	}

	public static class Info{
		
		public List<Shop> shops = new ArrayList<Shop>();

		public List<String> pids = new ArrayList<>();
		
		public static class Shop{

			public boolean isSelect;
			
			public String cid, pid, title, picurl,unit, one, two;

			public int number;

			public double price;
			
		}
		
	}

}
